home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 May: Tool Chest / Developer CD Series Tool Chest (Apple Computer)(May 1999).iso / Tool Chest / Development Kits / MPW etc / MPW-GM / MPW / Examples / PPCExamples / CExamples / PPC-68K / Wrapper.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-12-03  |  1.5 KB  |  60 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        Wrapper.c
  3.  
  4.     Contains:    Single entry-point code resource that sets up a series
  5.                 of pointers to library functions.
  6.                 A key part of the "calling 68K code from PowerPC" demo
  7.  
  8.     Written by:    Richard Clark
  9.  
  10.     Copyright:    © 1994 by Apple Computer, Inc., all rights reserved.
  11.  
  12.     Change History (most recent first):
  13.  
  14.                  2/15/94    RC        Released
  15.  
  16.     To Do:
  17. */
  18.  
  19. #include "Library.h"
  20. #include "WrapperTable.h"
  21. #include <TextUtils.h>
  22. #include <CodeFragments.h>
  23.  
  24.  
  25.  
  26. pascal void Wrapper(void)
  27. // Build a table of pointers to functions in our linked library
  28. {
  29.     OSErr            err;
  30.     CFragConnectionID connID = 0;
  31.     Ptr                mainAddr;
  32.     Str255             errName, appName, tableName;
  33.     CFragSymbolClass symClass;
  34.     JumpTablePtr    myTablePointer;
  35.  
  36.     _DataInit();
  37.     
  38.     // Locate the application that called us
  39.     GetIndString( (unsigned char *)&appName, 128, 1);
  40.     err = GetSharedLibrary( (unsigned char *)&appName, kPowerPCCFragArch, 0, &connID, &mainAddr, (unsigned char *)&errName);
  41.     if (err) goto done;
  42.     
  43.     // Now, locate the table that is shared between the 68K code and the PowerPC code
  44.     // (it's a pointer stored in a global variable)
  45.     GetIndString( (unsigned char *)&tableName, 128, 2);
  46.     err = FindSymbol(connID, (unsigned char *)&tableName, (Ptr*)&myTablePointer, &symClass);
  47.     // We could check to see that symClass == dataSymbol, but I'm in a trusting mood today
  48.     if (err) goto done;
  49.     
  50.     // Fill in the table with pointers to each library function
  51.     myTablePointer->routine1 = NewMyRoutineProc(LibFunction);
  52.     
  53. done:
  54.     if (connID)
  55.         CloseConnection(&connID);
  56. }
  57.  
  58.  
  59. // Link the library on after this...
  60.